import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:xiongan_app_yy/common/user_singleton.dart';
import 'package:xiongan_app_yy/net/internet_api.dart';
import 'package:xiongan_app_yy/pages/common/LoadBuilder.dart';
import 'package:xiongan_app_yy/provider/automounting_provider.dart';
import 'package:xiongan_app_yy/utils/toast_utils.dart';
import 'package:xiongan_app_yy/widgets/into_warehousing_item.dart';
import 'package:xiongan_app_yy/widgets/search_widget.dart';

class WarehousingSearchPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return WarehousingSearchPageState();
  }
}

class WarehousingSearchPageState extends State<WarehousingSearchPage>{
  int size=0;
  List<dynamic> data;
  @override
  Widget build(BuildContext context) {
    return SearchWidget(tipsText: "请输入入库任务单号",onTapFuns: (value){
      if(value!=null&&value.toString().length>0){
        onSearch(value);
      }else{
        TostUtil.showToast("请输入入库任务单号");
      }

    },child: LoadBuilder(
    visibility: false,
    emptyVisibility: size == 0,
    emptyTextVisibility: size == 0,
    textEmptyTips: "暂无内容",
    builder: ListView.separated(
        itemBuilder: (BuildContext context, int index) {
          return IntoWareHousingItem(data[index], index,
                  (id, name) {
                if (name.contains("待入库")||name.contains("清点中")) {
                  Navigator.pushNamed(context, '/invCounterDetails',
                      arguments: data[index]);
                } else if (name.contains("交接") ||
                    name.contains("清点完成")) {
                  Navigator.pushNamed(
                      context, '/into_handover_details',
                      arguments: data[index]);
                } else if (name.contains("上架")) {
                  Provider.of<AutoMountingProvider>(context).getDetailListData(orderid: data[index]['id']);
                  Provider.of<AutoMountingProvider>(context).setOrderId(data[index]['id']);
                  Navigator.pushNamed(
                      context, '/auto_mounting_type');
                }
              });
        },
        separatorBuilder: (BuildContext context, int index) =>
            Divider(height: 1, color: Colors.transparent),
        itemCount: size)),
    );
  }

  void onSearch(String str) {
    InternetAPI.getInstance()
        .get("WMS/MiWarehouseInOrder/GetAllMiWarehouseInOrderList", (value) {
      setState(() {
        data = value;
        size = data.length;
      });
    }, params: {
      'operaterUserId': DataSingleton().Data.id,
      'tenantId': DataSingleton().Data.tenantId,
      "userid": DataSingleton().Data.id,
      "warehouseid":DataSingleton().warehouseChoice.id,
      "appointmentmode":"20",
      "orderno":str,
      "pageNo":-1,
    });

  }
}